import requests
from lxml import etree
import xlwt
from xlwt import Workbook
import re

book = Workbook(encoding='utf-8')
sheet1 = book.add_sheet('中国地震网实时信息')

url = "http://www.ceic.ac.cn/speedsearch"
response = requests.get(url)
xml = etree.HTML(response.text)
all_list = xml.xpath('//div[@class="speedquery"]/div[1]/table/tr//text()')
b = []
for a in all_list:
    c = re.sub(r'\s','',a+'')
    if c != '':
        b.append(c)
for i in range(1,int(len(b)/6)):
    b[6*i+1] = b[6*i+1][:10]+' '+b[6*i+1][10:]
#print(b)

for i in range(0,int(len(b)/6)):  #行
    for j in range(0,6):     #列
        #print(b[6*i+j],'  ',end='')
        sheet1.write(i,j,b[6*i+j])
    #print("\n")
zuixintime = all_list[17][0:10]
#保存表格
import datetime
now_time = str(datetime.datetime.now())[0:10]
title = now_time+'.xlsx'
book.save(title)
